package com.rt.easyjava.common.base;


import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;

import java.io.Serializable;
import java.util.Date;

public class CommonBean<B extends CommonBean<?>> extends Model<B> {

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    private Integer deleteflag;
    private Date createdate;
    private Date modifydate;
    private String createman;
    private Long createmanId;
    private String modifyman;
    private Long modifymanId;
    private Long companyId;


    // 重写这个方法，return当前类的主键
    @Override
    protected Serializable pkVal() {
        return id;
    }


    // set deleteflag default 0, 查询参数时，默认只查有效数据
    public void setDeleteflagDefaultZero(){
        if(this.deleteflag==null){
            this.setDeleteflag(0);
        }
    }

    // 数据访问边界 0：全部数据， 10：机构内部数据
    public void rebuildDataLimitQueryBean(UserDetailsDto userDetailsDto){
        if (userDetailsDto==null) return;
        int dataLimitType = userDetailsDto.getDataLimitType();
        if (dataLimitType >= 10) {
            this.setCompanyId(Long.parseLong(userDetailsDto.getCompanyId()));
        }
        if (dataLimitType >= 20) {
            this.setCreatemanId(Long.parseLong(userDetailsDto.getUserId()));
        }
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Integer getDeleteflag() {
        return deleteflag;
    }

    public void setDeleteflag(Integer deleteflag) {
        this.deleteflag = deleteflag;
    }

    public Date getCreatedate() {
        return createdate;
    }

    public void setCreatedate(Date createdate) {
        this.createdate = createdate;
    }

    public Date getModifydate() {
        return modifydate;
    }

    public void setModifydate(Date modifydate) {
        this.modifydate = modifydate;
    }

    public String getCreateman() {
        return createman;
    }

    public void setCreateman(String createman) {
        this.createman = createman;
    }

    public Long getCreatemanId() {
        return createmanId;
    }

    public void setCreatemanId(Long createmanId) {
        this.createmanId = createmanId;
    }

    public String getModifyman() {
        return modifyman;
    }

    public void setModifyman(String modifyman) {
        this.modifyman = modifyman;
    }

    public Long getModifymanId() {
        return modifymanId;
    }

    public void setModifymanId(Long modifymanId) {
        this.modifymanId = modifymanId;
    }

    public Long getCompanyId() {
        return companyId;
    }

    public void setCompanyId(Long companyId) {
        this.companyId = companyId;
    }
}
